package com.hqyj.controller;

import com.hqyj.pojo.ManagerManagerInfo;
import com.hqyj.service.ManagerManagerInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;

@Controller
@RequestMapping("/manager-manager")
public class ManagerManagerInfoController {

    @Autowired
    ManagerManagerInfoService managerManagerInfoService;
    @RequestMapping("/managerlist")
    public String list(ManagerManagerInfo manager, ModelMap m){

        HashMap<String,Object> map= managerManagerInfoService.managerselect(manager);

        m.put("qaq",map);
        //把用户输入的查询条件传到前端
        m.put("vv",manager.getConValue());
        return "manager-manager/manager-list";
    }
    //处理表格的ajax数据
    @RequestMapping("/listAjax")
    @ResponseBody
    public HashMap<String,Object> listAjax(ManagerManagerInfo manager){
        return managerManagerInfoService.managerselect(manager);
    }
    @RequestMapping("/managereditPage")
    public String editPage(ManagerManagerInfo manager, ModelMap m){
        //根据managerId查询
        ManagerManagerInfo q = managerManagerInfoService.selectByManagerId(manager);
        //把数据传到前端
        m.addAttribute("manager",q);
        return "manager-manager/manager-edit";
    }
    //处理修改的ajax请求
    @RequestMapping("/manageredit")
    @ResponseBody
    public HashMap<String,Object> edit(ManagerManagerInfo manager){
        HashMap<String,Object> map=new HashMap<String, Object>();
        String info = managerManagerInfoService.update(manager);
        map.put("info",info);
        return map;
    }
    //处理删除的ajax请求
    @RequestMapping("/managerdel")
    @ResponseBody
    public HashMap<String,Object> del(ManagerManagerInfo manager){
        HashMap<String,Object> map=new HashMap<String, Object>();
        String info = managerManagerInfoService.del(manager);
        map.put("info",info);
        return map;
    }
    @RequestMapping("/addPage")
    public String addPage(ManagerManagerInfo manager, ModelMap m){

        return "manager-manager/manager-add";
    }
    //处理新建请求
    @RequestMapping("/xinjian")
    @ResponseBody
    public HashMap<String,Object> xinjian(ManagerManagerInfo manager){

        HashMap<String,Object> map=new HashMap<String, Object>();
        //访问注册方法
        String info = managerManagerInfoService.xinjian(manager);
        map.put("info",info);

        return  map;
    }
    //访问lead界面
    @RequestMapping("/lead")
    public String lead(){ return "manager-manager/lead";}


}
